Skip to main content

API controllers

Plugins can provide custom API controllers that can be exposed by Bank Admin in a dedicated plugin API. These controllers can be used to provide data for creating Insights Definitions audience and triggering conditions in the admin panel.

Implementation

Controllers use Repositories as a data source. Only repositories that provide generic data such as categories, currencies, merchants, etc. can be used. Repositories that retrieve user data (implementing the IUserRepository interface) cannot be used in controllers.

An example implementation of a plugin API controller might look like the following:

[Route("categories")]
public class CategoryController : PluginControllerBase
{
private readonly ICategoryRepository _categoryRepository;

public CategoryController(
ICategoryRepository categoryRepository)
{
_categoryRepository = categoryRepository;
}

/// <summary>
/// Returns available categories
/// </summary>
/// <returns>Available categories.</returns>
[HttpGet]
[ProducesResponseType(typeof(JsonApiDocument<IList<Category>>), (int)HttpStatusCode.OK)]
public IActionResult GetCategories()
{
return Ok(new JsonApiDocument<IList<Category>>(_categoryRepository.Categories));
}
}

Meniga provides ready-to-use controllers in the Meniga.InsightsFactory.DigitalBankingContracts library. All that is needed is to reference this library in the plugin dedicated to the Banking Admin like this:

public class BankAdminPluginInstaller : IBankAdminPluginInstaller
{
...

public IEnumerable<Assembly> DependantAssemblies => new[]
{ typeof(Meniga.InsightsFactory.DigitalBankingContracts.Controllers.PluginControllerBase).Assembly };

...
}

The contracts library contains an abstract class PluginControllerBase from which custom controllers should inherit. However, the contracts library is optional. In this case, instead of inheriting from above class, use IPluginController from Meniga.InsightsFactory.BankAdmin.Contracts.External library.

Once successfully installed Plugin controller should be visible in Bank Admin Swagger under a dedicated schema definition based on the Plugin assembly unique name.

Digital Banking Plugin Swagger definition hosted by Bank Admin

It is possible to implement custom controllers as well. If the controllers are placed in the main plugin library, they will automatically be added to Bank Admin. However, if they are placed in a dependent library, then such a dependency must be registered. How to do it see this section.